#version 450 core

layout (location = 0) out vec4 o_Color;
//out int o_EntityID;

struct VertexOutput
{
	vec4 Color;
	vec2 TexCoord;
	float TilingFactor;
	vec2 UV;
};

layout (location = 0) in VertexOutput Output;
layout (location = 4) in float v_TexIndex;
layout (location = 5) in flat int v_EntityID;

uniform mediump vec2 TextureSize0;
uniform lowp float Time; 

uniform sampler2D u_Textures[5];

#define PI 3.14

void main()
{
	vec4 texColor = Output.Color;
    vec2 uv = Output.TexCoord * Output.TilingFactor;
    vec2 UV = uv;

	switch(int(v_TexIndex))
	{
		//case  0: texColor *= texture(u_Textures[0], uv); break;
	}

    float ratio = TextureSize0.x / TextureSize0.y;

    uv = uv * 2.0 - 1.0;
    uv.x *= ratio;
    
    vec2 uv0 = uv;
    vec3 finalColor = vec3(0.0);

    vec2 p = uv;
    float len = length(p);
    float n1 = mod(Time*0.4, PI/4.0);//0-90
    float n2 = mod(Time*0.4 + PI/8.0, PI/4.0);//0-90

    float time1 = sin(n1)*3.0;
    float time2 = sin(n2)*3.0;

    float wave = sin(13.0*len*PI)/5.0;//波数与偏移量
    float limit1 = clamp(0.2-abs((time1)-len),0.0,1.0);//水波的限制
    float limit2 = clamp(0.2-abs((time2)-len),0.0,1.0);//水波的限制
    vec2 offset = normalize(p)*wave*(limit1+limit2);

    texColor *= texture(u_Textures[0], UV+offset);
    texColor.rgb += vec3(dot(offset,offset))*50.0;//高亮调节

	if (texColor.a == 0.0)
		discard;

	o_Color = texColor;
	//o_Color = vec4(uv.x, uv.y, 0.0, 1.0);
}
